<template>
	<!-- <view style="display: flex;flex-direction: column;"> -->
		<view class="container">
			<image src="http://192.168.137.1:8080/image/pay.jpg" style="width: 300px;height: 400px;margin-top: 40px;"></image>
			<text style="color: #7F7F7F;font-size: 15px;margin-top: 10px;">请先保存二维码图片再前往支付</text>
			<button type="default" style="width: 200px;height: 48px;margin-top: 20px;background-color: #469ce1;color: #FFFFFF;" @click="openalipay(orderid)">前往支付</button>
			<!-- <button type="default" style="width: 200px;height: 48px;margin-top: 40px;" @click="havepayed(orderid)">已完成支付</button> -->
			<button type="default" style="width: 200px;height: 48px;margin-top: 40px;" @click="nothavepayed()">稍后支付</button>
		
		</view>
		
	<!-- </view> -->
</template>

<script>
	export default{
		data(){
			return{
				orderid:"",
				flag:"",
				shopname:"",
				totalprice:"",
			}
		},
		
		onLoad:function(option){
			this.flag=option.fromwhere
			this.shopname=option.shopname
			this.totalprice=option.totalprice
			
			//如果是从submit订单过来的：
			if(option.fromwhere=="submit"){
				//禁用本页面左滑返回
				var page = this.$mp.page.$getAppWebview();
				page.setStyle({ popGesture: 'none' });
				this.orderid=option.orderid
			}
			
			// 如果是从订单列表过来支付的:
			else{
				this.orderid=option.orderid
				return;
			}
			
		
		},
		// onShow() {
		// 	//禁用本页面左滑返回
		// 	var page = this.$mp.page.$getAppWebview();
		// 	page.setStyle({ popGesture: 'none' });
		// },
		methods:{
			havepayed(orderid){
				//修改订单状态(走后台)
				uni.request({
					url:getApp().globalData.http+"/order/pay",
					method:"POST",
					header:{
						'content-type':"application/x-www-form-urlencoded",
						"Authorization":uni.getStorageSync("token")
					},
					data:{
						orderid:orderid,
						flag:"pay"
					},
					success: (res) => {
						if(res.data=="success"){
							getApp().submitorder="true"//判断是否是提交订单后跳到订单页面的
							uni.switchTab({
								url:"../../order/order",
								
								
							});
						}
						else{
							uni.showToast({
								title:"请稍后再试"
							})
						}
					}
					
				})

			},
			nothavepayed(){
				//如果是从提交订单过来的,回到tabbar=订单
				if(this.flag=="submit"){
					getApp().submitorder="true"//判断是否是提交订单后跳到订单页面的
					uni.switchTab({
						url:"../../order/order",
						
					});
				}
				
				// 如果是从当前订单过来的,回到上一页
				else{
					uni.navigateBack({
						delta:getCurrentPages().length-3
					})
					
				}
				
				
			},
			// 前往支付
			openalipay(orderid){
				//拉起支付宝扫码
				 // plus.runtime.launchApplication( {  
				 //                    action:"alipayqr://platformapi/startapp?saId=10000007"})
		 
				uni.request({
					url:getApp().globalData.http+"/pay",
					method:"POST",
					header:{
						'Authorization' : uni.getStorageSync("token"),
						'content-type':"application/x-www-form-urlencoded"
					},
					data:{
						shopname:this.shopname,
						totalprice:this.totalprice
					},
					success: (res) => {
				
						
						const jyAliPay = uni.requireNativePlugin('JY-ALIPAY')
						jyAliPay.show({ // 发起支付
						    if_sanbox:true, 
						    auto_create_order_info:false,
						  
						    
						    order_info:res.data
						}, function (result) { // 支付完成回调
						    console.log(result)
						     if(result.resultStatus == '5002555')
						     {
						         that.vusui.msg('支付sdk出错')
						     }
							 if(result.resultStatus == '9000')
						     {
						         // that.vusui.msg('支付成功')
								 
								 //修改订单状态(走后台)
								 uni.request({
								 	url:getApp().globalData.http+"/order/pay",
								 	method:"POST",
								 	header:{
								 		'content-type':"application/x-www-form-urlencoded",
								 		"Authorization":uni.getStorageSync("token")
								 	},
								 	data:{
								 		orderid:orderid,
								 		flag:"pay"
								 	},
								 	success: (res) => {
								 		if(res.data=="success"){
								 			getApp().submitorder="true"//判断是否是提交订单后跳到订单页面的
								 			uni.switchTab({
								 				url:"../../order/order",
								 				
								 				
								 			});
								 		}
								 		else{
								 			uni.showToast({
								 				title:"请稍后再试"
								 			})
								 		}
								 	}
								 	
								 })
								 
								 
						     }else{
						         // that.vusui.msg(result.memo)
						     } 
						  
						
						  
						  
						  
						});
							
					}
				})
		 
			}
			
		}
		
	}
</script>

<style scoped>
	.container{
		/* background-image: url('../../../static/IMG_2116.png'); */
	 	width: 100%;
		height: 100%; 
		/* background-color: #09BB07; */
		align-items: center;
		display: flex;
		flex-direction: column;
	}
</style>
